import java.awt.Color;
import java.awt.Graphics2D;

/**
 * @author Abubakr
 * 
 */
public class PacMan {
	int[] xPoints;
	int[] yPoints;
	int nPoints = 3;

	public PacMan() {

	}

	public void drawPacMan(Graphics2D g2, int x, int y, Board board, int dir, boolean mouth) {
		g2.fillOval(x * board.getBoardSize(), y * board.getBoardSize(),
				board.getBoardSize(), board.getBoardSize());
		if (mouth){
			if (dir == 0) {
				yPoints = new int[] { y * board.getBoardSize(),
						(y * board.getBoardSize()) + (board.getBoardSize() / 2),
						y * board.getBoardSize() };
				xPoints = new int[] {
						x * board.getBoardSize() + (board.getBoardSize() / 3),
						(x * board.getBoardSize()) + (board.getBoardSize() / 2),
						(x + 1) * board.getBoardSize() - (board.getBoardSize() / 3) };
			} else if (dir == 1) {
				yPoints = new int[] {
						y * board.getBoardSize() + (board.getBoardSize() / 3),
						(y * board.getBoardSize()) + (board.getBoardSize() / 2),
						(y + 1) * board.getBoardSize() - (board.getBoardSize() / 3) };
				xPoints = new int[] { (x + 1) * board.getBoardSize(),
						(x * board.getBoardSize()) + (board.getBoardSize() / 2),
						(x + 1) * board.getBoardSize() };
			} else if (dir == 2) {
				yPoints = new int[] { (y + 1) * board.getBoardSize(),
						(y * board.getBoardSize()) + (board.getBoardSize() / 2),
						(y + 1) * board.getBoardSize() };
				xPoints = new int[] {
						x * board.getBoardSize() + (board.getBoardSize() / 3),
						(x * board.getBoardSize()) + (board.getBoardSize() / 2),
						(x + 1) * board.getBoardSize() - (board.getBoardSize() / 3) };
			} else {
				yPoints = new int[] {
						y * board.getBoardSize() + (board.getBoardSize() / 3),
						(y * board.getBoardSize()) + (board.getBoardSize() / 2),
						(y + 1) * board.getBoardSize() - (board.getBoardSize() / 3) };
				xPoints = new int[] { x * board.getBoardSize(),
						(x * board.getBoardSize()) + (board.getBoardSize() / 2),
						x * board.getBoardSize() };
			}
			
		} else {
			if (dir == 0) {
				yPoints = new int[] { y * board.getBoardSize(),
						(y * board.getBoardSize()) + (board.getBoardSize() / 2),
						y * board.getBoardSize() };
				xPoints = new int[] {
						x * board.getBoardSize() + (board.getBoardSize() / 2),
						(x * board.getBoardSize()) + (board.getBoardSize() / 2),
						(x + 1) * board.getBoardSize() - (board.getBoardSize() / 2) };
			} else if (dir == 1) {
				yPoints = new int[] {
						y * board.getBoardSize() + (board.getBoardSize() / 2),
						(y * board.getBoardSize()) + (board.getBoardSize() / 2),
						(y + 1) * board.getBoardSize() - (board.getBoardSize() / 2) };
				xPoints = new int[] { (x + 1) * board.getBoardSize(),
						(x * board.getBoardSize()) + (board.getBoardSize() / 2),
						(x + 1) * board.getBoardSize() };
			} else if (dir == 2) {
				yPoints = new int[] { (y + 1) * board.getBoardSize(),
						(y * board.getBoardSize()) + (board.getBoardSize() / 2),
						(y + 1) * board.getBoardSize() };
				xPoints = new int[] {
						x * board.getBoardSize() + (board.getBoardSize() / 2),
						(x * board.getBoardSize()) + (board.getBoardSize() / 2),
						(x + 1) * board.getBoardSize() - (board.getBoardSize() / 2) };
			} else {
				yPoints = new int[] {
						y * board.getBoardSize() + (board.getBoardSize() / 2),
						(y * board.getBoardSize()) + (board.getBoardSize() / 2),
						(y + 1) * board.getBoardSize() - (board.getBoardSize() / 2) };
				xPoints = new int[] { x * board.getBoardSize(),
						(x * board.getBoardSize()) + (board.getBoardSize() / 2),
						x * board.getBoardSize() };
			}
		}
		g2.setColor(Color.BLACK);
		g2.fillPolygon(xPoints, yPoints, nPoints);
		
	}
}
